package arithmetic.jinritoutiao1;

import java.util.Scanner;

/**
 * Created by jiangfeng on 2018/3/24.
 */
public class Main {

    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        int n = sc.nextInt();
//        int ans = 0, x;
//        for (int i = 0; i < n; i++) {
//            for (int j = 0; j < n; j++) {
//                x = sc.nextInt();
//                ans += x;
//            }
//        }
//        System.out.println(ans);
        LED led = new LED();
        char[][] chss = led.getLED("0123456789");
        LED.print(chss);


    }

    static class LED {

        /**
         * ÿ�� LED �Ĵ�С�����Խ��е���
         */
        public final static int ROW = 5;
        public final static int COL = 5;

        /**
         * ÿ�� LED �ļ��
         */
        private final static int SEPARATOR = 1;

        private final static char FILL_CHAR = '6';
        private final static char SPACE_CHAR = ' ';

        /**
         * ���߷������������ LED
         */
        public static void print(char[][] chs) {
            for (int i = 0; i < chs.length; i++) {
                for (int j = 0; j < chs[i].length; j++) {
                    System.out.print(chs[i][j]);
                }
                System.out.println();
            }
        }

        /**
         * �������ֵõ� LED ��ʾ����
         */
        public char[][] getLED(String num) {
            char[] chs = num.toCharArray();
            char[][][] chsss = new char[chs.length][][];
            for (int i = 0; i < chs.length; i++) {
                chsss[i] = showLed(chs[i] - '0');
            }
            return putManyLed(chsss);
        }

        /**
         * ����� LED ���һ��
         */
        private char[][] putManyLed(char[][][] chsss) {
            if (chsss.length < 1) {
                throw new IllegalArgumentException("LED is NULL!");
            }
            if (chsss.length == 1) {
                return chsss[0];
            }
            char[][] chss = new char[ROW][chsss.length * (COL + SEPARATOR) - SEPARATOR];
            for (int i = 0; i < chsss.length; i++) {
                int m = i * (COL + SEPARATOR);
                for (int j = 0; j < chsss[i].length; j++) {
                    for (int k = 0; k < chsss[i][j].length; k++) {
                        chss[j][m + k] = chsss[i][j][k];
                    }
                }
            }
            for (int i = 0; i < chss.length; i++) {
                for (int j = 0; j < chss[i].length; j++) {
                    if (chss[i][j] != FILL_CHAR) {
                        chss[i][j] = SPACE_CHAR;
                    }
                }
            }
            return chss;
        }

        /**
         *
         */
        private char[][] showLed(int num) {
            boolean[] b = getLed(num);
            char[][] chs = new char[ROW][COL];
            if (b[0]) {
                for (int i = 0; i < COL; i++) {
                    chs[0][i] = FILL_CHAR;
                }
            }
            if (b[1]) {
                for (int i = 0; i <= ROW / 2; i++) {
                    chs[i][COL - 1] = FILL_CHAR;
                }
            }
            if (b[2]) {
                for (int i = ROW / 2; i < ROW; i++) {
                    chs[i][COL - 1] = FILL_CHAR;
                }
            }
            if (b[3]) {
                for (int i = 0; i < COL; i++) {
                    chs[ROW - 1][i] = FILL_CHAR;
                }
            }
            if (b[4]) {
                for (int i = ROW / 2; i < ROW; i++) {
                    chs[i][0] = FILL_CHAR;
                }
            }
            if (b[5]) {
                for (int i = 0; i <= ROW / 2; i++) {
                    chs[i][0] = FILL_CHAR;
                }
            }
            if (b[6]) {
                for (int i = 0; i < COL; i++) {
                    chs[ROW / 2][i] = FILL_CHAR;
                }
            }
            return chs;
        }

        /**
         * ������
         *
         * 0 ####### #     # 1 5 #  6  # ####### #     # 4 #     # 2 ####### 3
         *
         * 0 ��ʾ leds[0]����Ϊ true ��ʾ�� LED ��ʾ��������ʾ
         */
        private boolean[] getLed(int num) {
            boolean a = (num & 8) >>> 3 == 1;
            boolean b = (num & 4) >>> 2 == 1;
            boolean c = (num & 2) >>> 1 == 1;
            boolean d = (num & 1) == 1;
            boolean[] leds = new boolean[7];
            leds[0] = (!a & !b & !c & d) | (b & !d);
            leds[1] = (b & !c & d) | (b & c & !d);
            leds[2] = !b & c & !d;
            leds[3] = (b & !c & !d) | (!b & !c & d) | (b & c & d);
            leds[4] = d | (b & !c);
            leds[5] = (c & d) | (!b & c) | (!a & !b & d);
            leds[6] = (!a & !b & !c) | (b & c & d);
            for (int i = 0; i < 7; i++) {
                leds[i] = !leds[i];
            }
            return leds;
        }
    }
}
